

$(document).ready(function() {
	$.validator.addMethod("existValue",function(value,element){
		var flag = false;
		$.ajax({
			type:"post",
			//url:basePath+"/dic/validateValue",
			url:basePath+"/dic/validateValue",
			data:{"parentId":$("#parentId").val(),"id":$("#dictionaryId").val(),"value":value},
			async:false,
			success:function(data){
				 if(data.code == "0"){
					 flag =  true;
			        }
			}
		});
		return flag;
	},"该值已存在");
	
	//var url = basePath+"/dic/addDic";
	var url = basePath+"/dic/addDic";
	
	if($("#dictionaryId").val() != "" || $("#dictionaryId").val() == null){
		//url = basePath+"/dic/editDic";
		url = basePath+"/dic/editDic";
	}
	
	
	$(".form-horizontal").validate({
		rules:{
			dicValue:{
				required:true,
				maxlength:30,
				existValue:true
			},
			dicName:{
				required:true,
				maxlength:30
			}
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
		        type:"post",
		        url:url,
		        async:false,
		        //beforeSubmit: showRequest,
		        success: function(data){
		        	 layer.msg(data.msg,{time:1000});
		        	 setTimeout(function(){
		        		 parent.location.reload();
		        		 var index = parent.layer.getFrameIndex(window.name);
			        	 parent.layer.close(index);
		        	 },1000)
		        	 
		        	
		        }
		      });
		}
	});
	
});
